#ifndef _S_OLED_SSD1306_H_
#define _S_OLED_SSD1306_H_

#define S_OLED_SSD1306_USE_EXT_LIB                                    1

#define S_OLED_SSD1306_CMD_REG                                        0x00
#define S_OLED_SSD1306_DATA_REG                                       0x40

typedef struct
{
    void (*ssd1306_write)(unsigned char reg, unsigned char *data, unsigned short len);
    unsigned char colunm;
    unsigned char row;
    unsigned char Alternative_COM_pin_Enable;
    unsigned char uptodown_enable;
    unsigned char invert_enable;
    // unsigned char uptodown_state;
    void (*delay_ms)(unsigned short time);
#if S_OLED_SSD1306_USE_EXT_LIB
    void* (*oled_malloc)(int size);
    unsigned char **oled_buf;
#endif
}s_oled_ssd1306_t;

typedef enum
{
    oled_ssd1306_ok = 0,
    oled_delay_ms_not_config,
    oled_write_not_config,
#if S_OLED_SSD1306_USE_EXT_LIB
    oled_ssd1306_ext_oled_t_null,
    oled_ssd1306_ext_oled_t_malloc_not_config,
    oled_ssd1306_ext_oled_t_malloc_failed,
    oled_ssd1306_ext_oled_buf_null,
#endif
    oled_ssd1306_state_terminal,
}oled_ssd1306_state;

#if !S_OLED_SSD1306_USE_EXT_LIB
extern oled_ssd1306_state s_oled_ssd1306_show_char(s_oled_ssd1306_t *oled, unsigned char x, unsigned char y, unsigned char c);
#else


extern oled_ssd1306_state s_oled_ssd1306_ext_init(s_oled_ssd1306_t *oled);
extern oled_ssd1306_state s_oled_ssd1306_ext_uptodown_change(s_oled_ssd1306_t *oled);
extern oled_ssd1306_state s_oled_ssd1306_ext_clear(s_oled_ssd1306_t *oled);
extern oled_ssd1306_state s_oled_ssd1306_ext_draw_point(s_oled_ssd1306_t *oled, unsigned char x, unsigned char y, unsigned char point);
extern oled_ssd1306_state s_oled_ssd1306_ext_buf_draw(s_oled_ssd1306_t *oled);
#endif

extern oled_ssd1306_state s_oled_ssd1306_init(s_oled_ssd1306_t *oled);
extern void s_oled_ssd1306_para_init(s_oled_ssd1306_t *oled);
extern oled_ssd1306_state s_oled_ssd1306_set_brightness(s_oled_ssd1306_t *oled, unsigned char br);
extern oled_ssd1306_state s_oled_ssd1306_clear(s_oled_ssd1306_t *oled);


extern void s_oled_ssd1306_test(void);
#endif
